home *** CD-ROM | disk | FTP | other *** search
- u
- DTV mod: C64 DTV in a C64 case
- http://joco.homeserver.hu/
-
- When I first heard about the C64DTV, I
- knew this is what I had been waiting
- for. I always wanted a clone compatible
- with the original C64, but more power-
- ful with extra resources like other
- resolutions, more memory, etc.
- Fortunately the C64DTV (I own a
- European PAL version V2) can be hacked:
-
- http://galaxy22.dyndns.org/dtv/v2
- /index.html
-
- Many ways, & you can find a lot of info
- about it on the Internet. See my
- referencesbelow!
-
- I checked many hacking pages, so I knew
- that it is possible to attach an
- original disk drive via the IEC bus, &
- it is possible to attach a PS2 keyboard
- to the unit. But as far as I know, no
- one tried to put the DTV back in an
- original C64 box (I can be wrong
- though). Then I found Lars
- Pontoppidan's MMC2IEC available here at
-
- http://pontoppidan.info/lars
- /index.php?proj=mmc2iec
-
- A project which uses MMC/SD card for
- storage & it acts like a 1541 drive
- (sure a little bit better).
-
- As I am experienced with micro-
- controllers as well as C/C++ &
- assembly language, I knew that there is
- a way to handle the original C64
- keyboard matrix with a microcontroller.
-
- Unfortunately the DTV does not have the
- keyboard rows/cols pinouts, so there
- is no perfect solution, but the PS2
- implementation might be good enough for
- my purposes.
-
- I thought, the same microcontroller -in
- this case it's the Atmel ATMEGA32 with
- 32 I/O pins - could scan the keyboard
- matrix & send necessary press & release
- codes on the PS2 bus to the DTV.
-
- The PS2 port on the DTV is
- unidirectional; it means the host never
- sends data to the keyboard. Great.
- Thanks to the other researches that
- cool guys have done before, I had
- enough knowledge about everything. I
- knew how to generate PS2 codes, I knew
- how to scan the keyboard matrix, &
- thanks to Lars Pontoppidan, I had a
- solution for the IEC interface. All I
- had to do is just modify the original
- MMC2IEC design a little bit, &
- implement the keyboard scanner
- function.
-
- I spent about 3 weekends with this.
- Unfortunately the PS2 interface for the
- DTV has some odds. It also has some
- remapping, therefore my implementation
- had to do some workaround for special
- keys. For example on the C64 keyboard
- the key 2 has the " sign when it's
- shifted, the PC keyboard has the sign
- @. There are some other mismatches,
- which made life difficult. Anyway, what
- you see here is the first version. I
- know it's not perfect, but it works.
-
- I do not want to write about the other
- obvious hacks for the DTV, you can find
- out yourselves (like joy port, video
- fix, updating the flash, etc), just
- Google them. I am not really concerned
- about the IEC & MMC stuff either, Lars
- did a great job. I am only writing
- about the keyboard matrix here.
-
- Theory: the IEC bus has higher priority
- than the keyboard matrix. Whenever the
- IEC works which means when you LOAD or
- SAVE something -there is no keyboard
- scanning. When there is no disk
- handling, the microcontroller has an
- idle time, in this case I scan the
- keyboard matrix as fast as I can. Every
- time I compare the last scanned values
- with the new ones, so in case of one
- key there are 4 different states
- (0-pressed, 1-released) if we have bit
- #1 as the old bit, & bit #0 is the new
- bit: 00: was pressed before & still
- pressed 01: was pressed, now it's
- released 10: was released, now it's
- pressed 11: was released, still
- released
-
- In case of 00 & 11 there is nothing to
- do, because the state of given key has
- not changed. If we get the 01 value, we
- have to generate a release code,
- whereas if we get the 10 value, we have
- to generate the press code.
-
- Because of the different keys (like 2/@
- - 2/" or 6/^ - 6/&) sometimes it's more
- complicated, so we need to change the
- code or virtually press or release the
- shifts. This is all done by the
- UpdateKeyMatrix() function.
-
- Let me highlight some points about the
- schematic. First of all, it's pretty
- simple. I used a 40PIN version of the
- microcontroller, where we have PORTA &
- PORTC on the "right side" of the chip.
- This makes the soldering very easy.
- I use the PORTA & PORTC for keyboard
- matrix (COLS & ROWS), but in this
- version I do not handle the RESTORE
- button. (maybe in the next version)
- I do not use LEDs, but they are on the
- PORTD bit #0 & bit #1. They were in the
- original MMC2IEC project but I just
- don't need them.
-
- Between the DTV & the AtMEGA micro-
- controller there are five data lines:
- PS2Data, PS2Clock, IECData, IECClock,
- IECAtn. These are on the PORTD.
-
- The PORTB is used to handle the SPI
- bus, this is what communicates with the
- SD/MMC card.
-
- I use the internal 8MHz clock source,
- but it's just around 7.6MHz because of
- the 3.3V Vcc voltage.
-
- Some points about the software: The
- main loop in the mmc2iec.c is pretty
- simple. It scans the keyboard if there
- is nothing else to do, otherwise the
- IEC handler works. Obviously I
- initialized the keyboard handler with
- the InitKeyMatrix() function before I
- use the UpdateKeyMatrix().
-
- While (TRUE) {SHIFT-+}
- // scan the keyboard normally (IDLE
- time)
-
- UpdateKeyMatrix()
- ;// IEC-MMC handler (LOAD/SAVE)
-
- Interface_handler()
- ; {SHIFT--}
- Ps2.c: this is the one that sends a
- byte on the PS2 bus to the DTV.
- Simple as hell, as the PS2 port is only
- output for the microcontroller. I am
- not even sure that the parity bit
- generation is correct. If not, that
- means the DTV does not care about the
- parity bit. Good.
-
- C64keymtx.c: the keyboard handler
- module. There is an array called "r"
- (unsigned char r[64] PROGMEM) which
- contains the PS2 codes. The only one
- exception is the colon ":" key, which
- is handled differently & I used 0xff
- for this key. Obviously, the table
- contains the keys based on the
- schematic - as you can see, the rows &
- cols are mixed, but it was the easiest
- way to solder & I did not mind changing
- the bits in the software. It doesnt
- matter anyway.
-
- How it works? Read the source. It tells
- everything.
-
- One more thing to mention. You will
- find out that I used the GOTO statement
- inside the UpdateKeyMatrix() to break
- up the loops some cases. I know that
- every book says you should never use
- GOTOs. Bull. I use what I want to use.
- And besides, this is a microcontroller
- application where speed & space are
- factors. I tried some different ways.
- Anything else generates more code. BTW
- the WINAVR is just perfect, the best
- compiler I've ever seen. Still, some
- bytes matter to me. So for those who
- are against the GOTO: try to write an
- assembly code without braches & jumps.
- Good luck for that. Gotos don't mix up
- your code. If they do for you, you
- should find another job to do.
- Selling postcards for example. :-)
-
- Downloads:
-
- The shematics of the project:
- http://joco.homeserver.hu
- /mmc2iecKB/img/sch.gif
- Source code:
- http://joco.homeserver.hu
- /mmc2iec KB/source.zip
-
- mixed with the original MMC2IEC code.
- You need WINAVR to compile
-
- Links & references:
-
- Lars Pontoppidan's page, MMC2IEC
- http://pontoppidan.info/lars
- /index.php?proj=mmc2iec
- DTV hacking:
- http://galaxy22.dyndns.org/dtv
- /v2/index.html
- Daniel Kahlin's webpage:
- http://www.kahlin.net/daniel
- /dtv/
-
- PonyProg, the application I use to
- program the Atmel microcontroller:
- http://www.lancos.com/prog.html
-
- A lo cost programmer for Atmel ATMEGA32
- http://gopchandani.wordpress.com
- /2007/01/18/the-atmega32programmer/
-
- (Don't forget to turn off the JTAG
- interface of the ATMEGA32, otherwise
- the PORTC won't work.)
-
- Things to do for the next release (just
- some ideas in my mind)
-
- Accurate RESTORE key handling. Well,
- there is no RESTORE handler at all now.
- LED's. Just to make it perfect.
- Modify the DTV's flash so I won't need
- to press the CTRL key always.
- Absoultely required. Video fix &
- dedicated video & audio ports on the
- box. Won't be too hard.
- Soldering the joy ports as well. I will
- do.
- Hack the original IEC routines to speed
- up the load & save. There must be a way
- as we can modify the FLASH.
-
- Thanks, Mr. Kahlin
-
- Addendum:
-
- -Here you can see the fusebits settings
- for the microcontroller: Fusebits
- Diagram Shown above -You can download
- the compiled version in intel-hex
- format: mmc2iec.hex
-
- http://joco.homeserver.hu/mmc2iecKB
- /mmc2iec.hex
- (right-click, then Save target as)
-
- Jozsef
- http://joco.homeserver.hu/
-
-